<?php
	require_once("action/dao/Connection.php");

	class AdminResearchDAO {
			
		public static function recherche($nompage,$id)
		{			
			$connection = Connection::connect();
			
			if($nompage=="ACCUEIL")
			{
				if(substr($id,0,1)=="n")
				{
					$query = "SELECT TITRE FROM B63_PAGESINFOS WHERE ID=:pidnumber";
				}
				elseif(substr($id,0,1)=="t")
					$query = "SELECT TEXTE FROM B63_PAGESINFOS WHERE ID=:pidnumber";
								
				
				$statement = oci_parse($connection, $query);
				oci_bind_by_name($statement, ":pidnumber",substr($id,1));			
			}
			
			if($nompage=="CARRIERES")
			{
				if(substr($id,0,1)=="e")
				{
					$query = "SELECT EMPLOI FROM B63_CARRIERES WHERE ID=:pidnumber";
				}
				elseif(substr($id,0,1)=="c")
					$query = "SELECT CONDITIONS FROM B63_CARRIERES WHERE ID=:pidnumber";
								
				
				$statement = oci_parse($connection, $query);
				oci_bind_by_name($statement, ":pidnumber",substr($id,1));			
			}
						
			if($nompage=="SERVICES")
			{
				if(substr($id,0,1)=="n")
				{
					$query = "SELECT NOM FROM B63_SERVICES WHERE ID=:pidnumber";
				}
				elseif(substr($id,0,1)=="d")
					$query = "SELECT DESCRIPTION FROM B63_SERVICES WHERE ID=:pidnumber";
								
				
				$statement = oci_parse($connection, $query);
				oci_bind_by_name($statement, ":pidnumber",substr($id,1));
			}
			
			if($nompage=="EQUIPE")
			{
				if(substr($id,0,1)=="n")
				{
					$query = "SELECT NOM FROM B63_EQUIPE WHERE ID=:pidnumber";
				}
				elseif(substr($id,0,1)=="f")
					$query = "SELECT FONCTION FROM B63_EQUIPE WHERE ID=:pidnumber";
				elseif(substr($id,0,1)=="d")
					$query = "SELECT DESCRIPTION FROM B63_EQUIPE WHERE ID=:pidnumber";			
				
				$statement = oci_parse($connection, $query);
				oci_bind_by_name($statement, ":pidnumber",substr($id,1));
			}
			
			oci_execute($statement);
						
			while ($row = oci_fetch_array($statement))
			{
				$reponse=$row[0]; //retourne une seule valeur
			}			
						
			Connection::close($connection);
			
			
			return $reponse;			
			
		}
		
		
		public static function update($nompage,$id,$texte)
		{
			$connection = Connection::connect();
			
			if($nompage=="ACCUEIL")
			{
				if(substr($id,0,1)=="n")
				{
					$query = "UPDATE B63_PAGESINFOS SET TITRE=:ptexte WHERE ID=:pidnumber";
				}
				elseif(substr($id,0,1)=="t")
					$query = "UPDATE B63_PAGESINFOS SET TEXTE=:ptexte WHERE ID=:pidnumber";
								
				$statement = oci_parse($connection, $query);
				oci_bind_by_name($statement, ":ptexte", $texte);
				oci_bind_by_name($statement, ":pidnumber",substr($id,1));			
			}
			
			if($nompage=="CARRIERES")
			{
				if(substr($id,0,1)=="e")
				{
					$query = "UPDATE B63_CARRIERES SET EMPLOI=:ptexte WHERE ID=:pidnumber";
				}
				elseif(substr($id,0,1)=="c")
					$query = "UPDATE B63_CARRIERES SET CONDITIONS=:ptexte WHERE ID=:pidnumber";
								
				$statement = oci_parse($connection, $query);
				oci_bind_by_name($statement, ":ptexte", $texte);
				oci_bind_by_name($statement, ":pidnumber",substr($id,1));			
			}
			
			if($nompage=="SERVICES")
			{
				if(substr($id,0,1)=="n")
				{
					$query = "UPDATE B63_SERVICES SET NOM=:ptexte WHERE ID=:pidnumber";
				}
				elseif(substr($id,0,1)=="d")
					$query = "UPDATE B63_SERVICES SET DESCRIPTION=:ptexte WHERE ID=:pidnumber";
								
				$statement = oci_parse($connection, $query);
				oci_bind_by_name($statement, ":ptexte", $texte);
				oci_bind_by_name($statement, ":pidnumber",substr($id,1));			
			}
			
			if($nompage=="EQUIPE")
			{
				if(substr($id,0,1)=="n")
				{
					$query = "UPDATE B63_EQUIPE SET NOM=:ptexte WHERE ID=:pidnumber";
				}
				elseif(substr($id,0,1)=="d")
					$query = "UPDATE B63_EQUIPE SET DESCRIPTION=:ptexte WHERE ID=:pidnumber";
				elseif(substr($id,0,1)=="d")
					$query = "UPDATE B63_EQUIPE SET FONCTION=:ptexte WHERE ID=:pidnumber";
								
				$statement = oci_parse($connection, $query);
				oci_bind_by_name($statement, ":ptexte", $texte);
				oci_bind_by_name($statement, ":pidnumber",substr($id,1));			
			}
			
			oci_execute($statement);
							
			Connection::close($connection);				
			
		}
		
}